
import shelve
def member_info(name, age):
   print("Member info:", name, age)
   
name = ['Jack', 'Maxwell', 'Tom']
info = {'name':'Maxwell', 'age':18}

# 1.持久化到文化
with shelve.open('demo') as data:
    data['name'] = name   #持久化列表
    data['info'] = info   #持久化字典
    data['member_info'] = member_info  #持久化函数
    
# 2.读取持久化数据
with shelve.open('demo') as data:
    print(data['name'])
    print(data['info'])
    data['member_info']('Jack', 20)
"""
['Jack', 'Maxwell', 'Tom']
{'name': 'Maxwell', 'age': 18}
Member info: Jack 20

"""